import pymysql


def print_m(self):
    print("*"*30)
    print("ID：%s"%self[0])
    print("学院：%s"%self[1])
    print("学号：%s"%self[2])
    print("姓名：%s"%self[3])
    print("身份证：%s"%self[4])
    print("性别：%s"%self[5])
    print("学历：%s"%self[6])
    print("专业：%s"%self[7])
    print("师范标志：%s"%self[8])
    print("师范生类别：%s"%self[9])
    print("困难生类别：%s"%self[10])
    print("培养方式：%s"%self[11])
    print("学制：%s"%self[12])
    print("民族：%s"%self[13])
    print("政治面貌：%s"%self[14])
    print("出生日期：%s"%self[15])
    print("入学时间：%s"%self[16])
    print("毕业时间：%s"%self[17])
    print("生源地区：%s"%self[18])
    print("城乡生源：%s"%self[19])
    print("家庭地址：%s"%self[20])
    print("家庭邮编：%s"%self[21])
    print("婚姻状况：%s"%self[22])
    print("考生号：%s"%self[23])
    print("联系方式：%s"%self[24])
    print("电邮：%s"%self[25])
    print("QQ：%s"%self[26])
    print("家庭电话：%s"%self[27])
    print("*" * 30)


def main():
    try:
        connection = pymysql.connect(
            host="192.168.21.130",
            port=3306,
            user="python",
            passwd="python",
            db="python",
            charset="utf8")
        cursor_test = connection.cursor()
        while True:
            input_name = input("\033[0;31m%s\033[0m" % "请输入要查询的学生姓名：")
            # 查询语句
            sql="select * from graduate where 姓名=%s"
            cursor_test.execute(sql,input_name)
            result = cursor_test.fetchone()
            print_m(result)
        # connection.commit()
        cursor_test.close()
        connection.close()
    except Exception as result:
        print("异常信息为：%s"%result)


if __name__ == '__main__':
    main()
